function [Overlap,Numerator] = ComputeSimilarity_Cosine(X)

%%%% This function computes the cosine similarity measure for all fund-pairs.

N = size(X,1);
K = size(X,2);

tmp = sum(X')';
X = X./repmat(tmp,1,K);

Norm = sqrt(sum(X'.^2))';
Overlap = X*X';
Numerator = Overlap;
Overlap = Overlap./(repmat(Norm,1,N).*repmat(Norm',N,1));

for i = 1:N
   Overlap(i,i) = NaN; 
end

Overlap(tmp<=0,:) = NaN;
Overlap(:,tmp<=0) = NaN;

end